home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / neural network tool and application / nsinstall.exe / data1.cab / DllSys_Files / ERRCRIT / LPC.C < prev   
Encoding:
C/C++ Source or Header  |  2002-03-08  |  1.7 KB  |  51 lines

  1. // Dynamic link library implementation of NeuroSolutions LpCriterion component 
  2.  
  3. #include "NSDLL.h" 
  4.  
  5. /***********************************/ 
  6. /* Forward activation of component */
  7.  
  8. __declspec(dllexport) NSFloat performCriterion(
  9.     DLLData    *instance,        // Pointer to instance data (may be NULL)
  10.     NSFloat *costDerivative,     // Pointer to the cost derivative vector, i.e. output sensitivity
  11.     int     rows,            // Number of rows of PEs in the layer
  12.     int     cols,            // Number of columns of PEs in the layer
  13.     NSFloat *output,         // Pointer to the output layer of the network
  14.     NSFloat *desired,        // Pointer to the desired output vector, same length as output layer
  15.     BOOL    testing            // Flag to indicate whether or not the data is for the test set
  16.     )
  17. {
  18.     int i,length=rows*cols;
  19.     NSFloat error, cost=0.0f;
  20.     int pConstant = getIntParameter(instance, 2, 1);
  21.  
  22.     for (i=0; i<length; i++) {
  23.         error = desired[i] - output[i];
  24.         costDerivative[i] = error*(NSFloat)fabs((NSFloat)pow((double)error, (double)pConstant-2));
  25.         cost += (NSFloat)fabs((NSFloat)pow((double)error, (double)pConstant));
  26.     }
  27.     cost *= 1.0f/(NSFloat)pConstant; 
  28.     return cost;
  29. }
  30.  
  31. /******************************************/
  32. /* Management of instance data (OPTIONAL) */
  33.  
  34. __declspec(dllexport) DLLData *allocCriterion(
  35.     DLLData    *oldInstance,    // Pointer to the last instance if reallocating
  36.     int     rows,        // Number of rows of PEs in the layer
  37.     int     cols        // Number of columns of PEs in the layer
  38.     )
  39. {
  40.     DLLData *instance = allocDLLInstance(oldInstance);
  41.     setParameterName(instance, 2, 1, "p", FALSE);
  42.     setIntParameter(instance, 2, 1, 5, FALSE);
  43.     return instance;
  44. }
  45.  
  46. __declspec(dllexport) void freeCriterion(DLLData *instance)
  47. {
  48.     freeDLLInstance(instance);
  49. }
  50.  
  51.